#include "sem.hpp"
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <pthread.h>
#include <sys/types.h>
#include <unistd.h>
void *ProductorRoutine(void *rq)
{
    RingQueue<int> *ringqueue = static_cast<RingQueue<int> *>(rq);
    while (true)
    {
        // sleep(3);
        int data = rand() % 10 + 1;
        ringqueue->Push(data);
        printf("生产完成, 生产的数据是: %d\n", data);
    }
}
void *ConsumerRoutine(void *rq)
{
    RingQueue<int> *ringqueue = static_cast<RingQueue<int> *>(rq);
    while (true)
    {
        int data;
        ringqueue->Pop(&data);
        printf("消费完成, 消费的数据是: %d\n", data);
        sleep(1);
    }
}
int main()
{
    srand((unsigned int)time(nullptr) ^ getpid() ^ pthread_self() ^ 0x71727374);
    RingQueue<int> *rq = new RingQueue<int>();
    pthread_t p, c;
    pthread_create(&p, nullptr, ProductorRoutine, rq);
    pthread_create(&c, nullptr, ConsumerRoutine, rq);
    pthread_join(p, nullptr);
    pthread_join(c, nullptr);
    delete rq;
    return 0;
}